
package com.jf.cloud.multishop.feign;

import com.jf.cloud.api.multishop.feign.ShopSubstituteSalesFeignClient;
import com.jf.cloud.common.cache.constant.CacheNames;
import com.jf.cloud.common.product.constant.SalesType;
import com.jf.cloud.common.response.ServerResponseEntity;
import com.jf.cloud.common.vo.ShopSubstituteSalesVO;
import com.jf.cloud.multishop.mapper.ShopSubstituteSalesMapper;
import com.jf.cloud.multishop.model.ShopSubstituteSales;
import com.jf.cloud.multishop.service.ShopSubstituteSalesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.v3.oas.annotations.Hidden;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author zz
 * @date 2022/6/24 15:38
 */
@RestController
@Hidden
public class ShopSubstituteSalesFeignController implements ShopSubstituteSalesFeignClient {
    @Autowired
    private ShopSubstituteSalesMapper shopSubstituteSalesMapper;

    @Autowired
    private ShopSubstituteSalesService shopSubstituteSalesService;

    @Override
    public ServerResponseEntity<ShopSubstituteSalesVO> getByShopSubstituteSalesId(Long shopId) {
        ShopSubstituteSalesVO byShopSubstituteSalesId = shopSubstituteSalesService.getByShopSubstituteSalesId(shopId);
        return ServerResponseEntity.success(byShopSubstituteSalesId);
    }

    @Override
    public ServerResponseEntity<List<ShopSubstituteSalesVO>> shopSubstituteSalesList(List<Long> shopIdList) {
        List<ShopSubstituteSalesVO> shopSubstituteSalesList  = new ArrayList<>();
        if (Objects.isNull(shopIdList) || shopIdList.size() == 0){
            return ServerResponseEntity.success(shopSubstituteSalesList );
        }
        shopSubstituteSalesList  = shopSubstituteSalesMapper.listByShopIds(shopIdList);
        return ServerResponseEntity.success(shopSubstituteSalesList );
    }

    @Override
    public ServerResponseEntity<Void> saveDefault(Long shopId) {
        // 保存店铺代销设置默认值
        ShopSubstituteSales shopSubstituteSales = new ShopSubstituteSales();
        shopSubstituteSales.setShopId(shopId);
        shopSubstituteSales.setSalesType(SalesType.MANUAL_OPERATION_PRICE.value());
        shopSubstituteSales.setOrderShape(0);
        shopSubstituteSalesService.save(shopSubstituteSales);
        return ServerResponseEntity.success();
    }
}
